package com.jml.ddd.sample.anemicdomainmodel.dao;

import com.jml.ddd.sample.anemicdomainmodel.model.Account;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

@Mapper
public interface AccountDao {

    @Select("SELECT * FROM ACCOUNT WHERE USER_ID = #{userId}")
    Account findByUserId(@Param("userId") String userId);

    @Update("UPDATE ACCOUNT SET balance = #{balance} , version = version+1 where id = #{id} and version = #{version}")
    int updateBalance(@Param("id") int id, @Param("balance") int balance,  @Param("version") Integer version);
}
